﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Entity;
using Entity.Admin;

namespace Web.Framework
{
    /// <summary>
    /// 自定义的控制器的基类
    /// </summary>
    public class BaseController : System.Web.Mvc.Controller
    {
        protected DBEntities db = new DBEntities();
        public List<string> WebAreas()
        {
            
            var routeList = this.Url.RouteCollection.Where(p => p.GetType() == typeof(System.Web.Routing.Route));
            var areaList = new List<string>();
            foreach (var item in routeList)
            {
                var areaName = ((System.Web.Routing.Route)item).DataTokens["area"] == null ? "" : ((System.Web.Routing.Route)item).DataTokens["area"].ToString();
                areaList.Add(areaName);
            }
            return areaList;
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }

        protected override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            string area = filterContext.RouteData.DataTokens["area"] == null ? "" : filterContext.RouteData.DataTokens["area"].ToString();
            string controller = filterContext.RouteData.Values["controller"] == null ? "" : filterContext.RouteData.Values["controller"].ToString();
            string action = filterContext.RouteData.Values["action"] == null ? "" : filterContext.RouteData.Values["action"].ToString();
            base.OnActionExecuting(filterContext);
        }
    }
}